CheckGradInfo.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. %===============================================================%
  2. % Checks gradiometer info for Custom-Filter & Control datasets: %
  3. % Last modified: Jan.15, 2014 %
  4. %===============================================================%
  5. % Copyright (C) 2013-2014, Michael J. Cheung
  6. %
  7. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  8. % details, see the documentation included with the software package.
  9. %
  10. % MEGPLS is free software: you can redistribute it and/or modify it under
  11. % the terms of the GNU General Public License version 2 as published by
  12. % the Free Software Foundation. This program is distributed in the hope
  13. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  14. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. % See the GNU General Public License for more details.
  16. %
  17. % You should have received a copy of the GNU General Public License along
  18. % with this program. If not, you can download the license here:
  19. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  20. function GradMismatch = CheckGradInfo(LoadedBuilderMat, RunSection)
  21. GradErrLog = fopen(['ErrorLog_',RunSection,'.txt'], 'a');
  22. % Load builder .mat file:
  23. name = LoadedBuilderMat.name;
  24. paths = LoadedBuilderMat.paths;
  25. gui = LoadedBuilderMat.gui;
  26. PipeSettings = LoadedBuilderMat.PipeSettings;
  27. SourceContrast = PipeSettings.Source.Contrast;
  28. EstNoiseCommonFilt = PipeSettings.Source.EstNoiseCommonFilt;
  29. % Only required for Fieldtrip data:
  30. if ~strcmp(gui.MEGdataFiletype, 'Fieldtrip') || isempty(paths.MEGdata)
  31. GradMismatch = 0;
  32. return;
  33. end
  34. % For DiffBase and EstNoise (No custom-filters):
  35. % No need to check grad info since filters are computed individually.
  36. if strcmp(SourceContrast, 'DiffBase') || ...
  37. strcmp(SourceContrast, 'EstNoise') && strcmp(EstNoiseCommonFilt, 'no')
  38. GradMismatch = 0;
  39. return;
  40. end
  41. %======================================================%
  42. % CHECK GRADIOMETER INFO OF CUSTOM & CONTROL DATASETS: %
  43. %======================================================%
  44. GradMismatch = 0;
  45. for g = 1:length(name.GroupID)
  46. for s = 1:length(name.SubjID{g})
  47. for c = 1:length(name.CondID)
  48. %--- Check grad. info for Common-Filter datasets: ---%
  49. %----------------------------------------------------%
  50. if strcmp(SourceContrast, 'EstNoise') && strcmp(EstNoiseCommonFilt, 'yes')
  51. MEGdataCommonFilt = LoadFTmat(paths.MEGdataCommonFilt{g}{s}, RunSection);
  52. if isempty(MEGdataCommonFilt)
  53. continue;
  54. end
  55. MEGdata = LoadFTmat(paths.MEGdata{g}{s,c}, RunSection);
  56. if isempty(MEGdata)
  57. continue;
  58. end
  59. if ~isequal(MEGdataCommonFilt.grad, MEGdata.grad)
  60. if GradMismatch == 0
  61. GradMismatch = 1;
  62. fprintf(GradErrLog, ['ERROR:'...
  63. '\n Datasets from which common-filters are computed from do '...
  64. '\n NOT have the same gradiometer info as their respective '...
  65. '\n input datasets. Common-filters cannot be applied. '...
  66. '\n'...
  67. '\n In order for common-filters to be used: '...
  68. '\n For each subject, the common-filter dataset and its '...
  69. '\n respective input datasets must have matching gradiometer '...
  70. '\n info (usually originating from the same MEG session). '...
  71. '\n'...
  72. '\n The following input datasets have different gradiometer '...
  73. '\n info from their respective common-filter datasets. \n\n']);
  74. end
  75. fprintf(GradErrLog, ' -> %s \n', paths.MEGdata{g}{s,c});
  76. end
  77. end
  78. %--- Check grad. info for DiffCond Control datasets: ---%
  79. %-------------------------------------------------------%
  80. if strcmp(SourceContrast, 'DiffCond')
  81. MEGdataControl = LoadFTmat(paths.MEGdataControl{g}{s}, RunSection);
  82. if isempty(MEGdataControl)
  83. continue;
  84. end
  85. MEGdataActive = LoadFTmat(paths.MEGdata{g}{s,c}, RunSection);
  86. if isempty(MEGdataActive)
  87. continue;
  88. end
  89. if ~isequal(MEGdataControl.grad, MEGdataActive.grad)
  90. if GradMismatch == 0
  91. GradMismatch = 1;
  92. fprintf(GradErrLog, ['ERROR:'...
  93. '\n Control datasets do NOT have the same gradiometer info '...
  94. '\n as their respective active condition datasets. Control '...
  95. '\n and active conditions cannot be merged for common-filter.'...
  96. '\n'...
  97. '\n As a result, the DiffCond setting (vs. Control Cond) '...
  98. '\n cannot be used. Gradiometer info must match (usually '...
  99. '\n originating from the same MEG session) in order for '...
  100. '\n common-filter to be computed across active & control. '...
  101. '\n'...
  102. '\n The following input datasets have different gradiometer '...
  103. '\n info from their respective control datasets. \n\n']);
  104. end
  105. fprintf(GradErrLog, ' -> %s \n', paths.MEGdata{g}{s,c});
  106. end
  107. end
  108. end % Cond
  109. end % Subj
  110. end % Group
  111. fclose(GradErrLog);